﻿using ControllerManageServer.ActionModel;
using ControllerManageServer.ActionModel.Aioi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerManageServer.LabelDevice.Aioi
{
    class MWU2414LabelDevice : BaseLabelDevice
    {

        public MWU2414LabelDevice()
        {
            SeqLength = 12;
        }

        /// <summary>
        /// MWU2414动作指令
        /// </summary>
        /// <param name="iModel">模式组合</param>
        /// <param name="iSeq">显示数据</param>
        /// <param name="iFnSeq">按下Fn后的显示数据</param>
        /// <returns></returns>
        public override byte[] Action(ActionModelAbstract iModel, string iSeq, string iFnSeq = null)
        {
            return Action(iModel, new string[] { iSeq/*, iFnSeq*/ });
        }

        /// <summary>
        /// MWU2414动作指令
        /// </summary>
        /// <param name="iModel">模式组合</param>
        /// <param name="iSeqArr">显示数据</param>
        /// <returns></returns>
        public byte[] Action(ActionModelAbstract iModel, string[] iSeqArr)
        {
            List<byte> result = new List<byte>();

            result.AddRange(DefaultEncoding.GetBytes("PQ1"));// 命令
            result.AddRange(DefaultEncoding.GetBytes("00"));// 区域号码
            result.AddRange(iModel.ModeArray());// 模式组合
            result.AddRange(DefaultEncoding.GetBytes("AF101"));
            result.AddRange(DefaultEncoding.GetBytes(Address));// 地址
            result.AddRange(DefaultEncoding.GetBytes("A"));
            if (iSeqArr == null && iSeqArr.Length == 0)
            {
                result.AddRange(DefaultEncoding.GetBytes("00"));
                return result.ToArray();
            }
            string temp;
            foreach (string seq in iSeqArr)
            {
                if (string.IsNullOrEmpty(seq)) continue;
                temp = SeqHandle(seq);
                if (result.Count + temp.Length + 2 > 1015) break;// 超出指定指令长度,则跳出循环
                result.AddRange(DefaultEncoding.GetBytes(temp.Length.ToString().PadLeft(2, '0')));// 显示字符长度
                result.AddRange(DefaultEncoding.GetBytes(temp));// 显示的字符
            }

            return result.ToArray();
        }
    }
}
